package com.landmesure.utils;


import com.util.ByteUtil;

public class PropertyBuilderOfBoolean implements PropertyBuilder {

	@Override
	public short[] buildProperty(int code, int len,String value) {
		short [] intByte = new short[len+1];
		intByte[0]=(short)code;
    	intByte[1] = (short) (Boolean.parseBoolean(value)?0:1);

		return intByte;
	}

	@Override
	public String translateData(byte[] datas,int len,int offset) {
		String value = ByteUtil.getIntNumber(offset, len, datas)==1?"true":"false";
		return value;
	}

	@Override
	public String encode(String pvalue, int length) {
		int value=Boolean.parseBoolean(pvalue)?1:0;
		switch (length){
        case 1:return String.format("%02X", value);
        case 2:return String.format("%04X", value);
        case 4:return String.format("%08X", value);
        }
		return null;
	}

	@Override
	public String decode(String pdata, int length) {
		return Integer.parseInt(pdata,16)==1?"true":"false";
	}

	@Override
	public Boolean parseValue(String pvalue) {
		return Boolean.parseBoolean(pvalue);
	}
    public static void main(String[] args){
    	System.out.println(Boolean.parseBoolean("0"));
    	System.out.println(Boolean.parseBoolean("1"));
    }
}
